#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn = 205;

int dp[maxn][maxn],a[maxn];

int main(){
	int n;
	cin>>n;
	for(int i = 1;i<=n;i++){
		cin>>a[i];
		a[n+i] = a[i];
	}
	
	n = n*2;
	a[n+1] = a[1];
	
	memset(dp,0xc0,sizeof dp);
	
	for(int i =1;i<=n;i++)	dp[i][i] = 0;
	
	for(int i=n;i>=1;i--){
		for(int j=i+1;j<=n;j++){
			for(int k=i;k<j;k++){
				dp[i][j] = max(dp[i][j],dp[i][k]+dp[k+1][j]+(a[i]*a[k+1]*a[j+1]));
			}
		}
	}
	
	n = n/2;
	int ans = 0xc0;
	for(int i=1;i<=n;i++){
		ans = max(ans,dp[i][i+n-1]);
	}
	cout<<ans<<endl;

}